<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="../classes/CommonHelper.class.jsp" %>
<%
int currentPage = 1;
if(!nullOrEmpty(request.getParameter("currentPage"))){
	currentPage = Integer.parseInt(request.getParameter("currentPage"));
	if(currentPage<1){
		currentPage = 1;
	}
}

//总记录数
int totalRecord = 0 ;
if(!nullOrEmpty(request.getParameter("totalRecord"))){
	totalRecord = Integer.parseInt(request.getParameter("totalRecord"));
}

String formName = request.getParameter("formName");

int pageSize = 20;
String url = request.getParameter("url");
if(!nullOrEmpty(request.getParameter("pageSize"))){
	pageSize = Integer.parseInt(request.getParameter("pageSize"));
}

int totalPage = 0;
if(totalRecord % pageSize != 0){
	totalPage = totalRecord / pageSize +1;
}else{
	totalPage = totalRecord / pageSize;
}
if(currentPage>totalPage){
	currentPage = totalPage;
}

//计算最小页数
int p = 0 ;
if(currentPage % 5 != 0){
	p = currentPage / 5;
}else{
	p = currentPage / 5-1;
}

if(currentPage<=1){
	out.println("<sapn'>首页<span>");
}else{
	out.println("<sapn><a href=\"javascript:submitPage(1,'"+formName+"')\" >首页</a><span>");
}
if(currentPage>1){

	out.println("<span class='upordown'><a href=\"javascript:submitPage("+(currentPage-1)+",'"+formName+"')\" >上一页</a></span>");
}
if(currentPage<=3){
	for(int i=1;i<=p*5+5 && i <= totalPage;i++){
		if(currentPage==i){
			out.println("<span class='active'><a href='javascript:;' >"+i+"</a></span>");
		}else{
			out.println("<span class='normal'><a href=\"javascript:submitPage("+i+",'"+formName+"')\" >"+i+"</a></span>");
		}
	}
}else{
	for(int i=currentPage-2;i<=currentPage+2 && i <= totalPage;i++){
		if(currentPage==i){
			out.println("<span class='active'><a href='javascript:;' >"+i+"</a></span>");
		}else{
			out.println("<span class='normal'><a href=\"javascript:submitPage("+i+",'"+formName+"')\" >"+i+"</a></span>");
		}
	}
}
if(currentPage<totalPage){
	out.println("<span class='upordown'><a href=\"javascript:submitPage("+(currentPage+1)+",'"+formName+"')\" >下一页</a></span>");
}
if(currentPage>=totalPage){
	out.println("<span>末页</span>");
}else{
	out.println("<span><a href=\"javascript:submitPage("+totalPage+",'"+formName+"')\" >末页</a></span>");
}
out.println("<span>第&nbsp;"+currentPage+"&nbsp;页 转<input type='text' style='width:25px;height:20px;' name='currentPage' id='currentPage' value='"+currentPage+"'>页 <a href=\"javascript:submitPage2('"+formName+"')\">GO</a> 共&nbsp;"+totalRecord+"&nbsp;条;&nbsp共&nbsp;"+totalPage+"&nbsp;页</span>");
%>
<script type="text/javascript">
function submitPage(currPage,formName)
{
	document.getElementById("currentPage").value=currPage;
	document.<%=formName%>.submit();
}

function submitPage2(formName){
	var curr = document.getElementById("currentPage").value;
	var numReg = /^[1-9]+([0-9]*)$/;
	if(!numReg.test(curr)){
		alert("请输入大约零的整数！");
		return;
	}
	document.<%=formName%>.submit();
}
</script>